package dna

import (
	"errors"
	"regexp"
	"strings"
)

const testVersion = 2

type Histogram map[rune]int

type DNA string

var Others = regexp.MustCompile(`[A|C|G|T]`)

func (dna DNA) Count(nucleotide byte) (r int, err error) {
	if nucleotide != 65 &&
		nucleotide != 67 &&
		nucleotide != 71 &&
		nucleotide != 84 {
		err = errors.New("nucleotide is not 'A', 'C', 'G', 'T'")
	}

	r = strings.Count(string(dna), string(nucleotide))
	return
}

func (dna DNA) Counts() (histogram Histogram, err error) {
	histogram = make(Histogram)

	if len(Others.FindAllString(string(dna), -1)) != len(string(dna)) {
		err = errors.New("errors")
		return
	}

	histogram['A'] = strings.Count(string(dna), "A")
	histogram['C'] = strings.Count(string(dna), "C")
	histogram['G'] = strings.Count(string(dna), "G")
	histogram['T'] = strings.Count(string(dna), "T")

	return
}
